local xianzhu = fk.CreateSkill {

  name = "joy__xianzhu",

  tags = {  },

}



xianzhu:addEffect("active", {
  name = "joy__xianzhu",
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isNude() and player:usedSkillTimes(xianzhu.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected, targets)
    return #selected == 0 and Fk:getCardById(to_select).sub_type == Card.SubtypeWeapon and Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id and not player:isProhibited(Fk:currentRoom():getPlayerById(to_select), Fk:cloneCard("slash"))
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:throwCard(effect.cards,xianzhu.name,player)
    local use = {
      from = player.id,
      tos = {{target.id}},
      card = Fk:cloneCard("slash"),
      skillName = xianzhu.name,
      extraUse = true,
    }
    room:useCard(use)
  end,
})

xianzhu:addEffect(fk.Damage, {
  name = "#joy__xianzhu_trigger",
  anim_type = "offensive",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xianzhu.name) and data.card and data.card.trueName == "slash" and
    table.find(player:getEquipments(Card.SubtypeWeapon), function(id) return Fk:getCardById(id).name == "joy__siege_engine" end)
    and (player:getMark("joy__xianzhu1") + player:getMark("joy__xianzhu2") + player:getMark("joy__xianzhu3")) < 5
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"joy__xianzhu2", "joy__xianzhu3"}
    if player:getMark("joy__xianzhu1") == 0 then
      table.insert(choices, 1, "joy__xianzhu1")
    end
    local choice = room:askForChoice(player, choices, xianzhu.name, "#xianzhu-choice")
    room:addPlayerMark(player, choice, 1)
  end,
})

return xianzhu